// const showError = require('./tipsFunc')
// post方法请求数据
function postData ({
  url,
  header,
  data,
  method = 'POST',
  success = () => { },
  failure = () => { },
  complete = () => { }
}) {
  wx.request({
    url: `${app.globalData.url}${url}`,
    data,
    method,
    header: {
      "content-type": "application/x-www-form-urlencoded", // 默认值
    },
    complete: (res) => {
      wx.hideLoading();
      complete(res);
      if (res.data) {
        return success(res.data);
      }
      failure(res.data);
    },
  });
}

// get方法请求数据
function getData ({
  url,
  header,
  data,
  method = 'GET',
  success = () => { },
  failure = () => { },
  complete = () => { }
}) {
  wx.request({
    url,
    data,
    method,
    header: {
      "content-type": "application/x-www-form-urlencoded", // 默认值
    },
    complete: (res) => {
      wx.hideLoading();
      complete(res);
      if (res.data) {
        return success(res.data);
      }
      failure(res.data);
    },
  });
}

module.exports.postData = postData
module.exports.getData = getData